package wli.hibernate.db;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import wli.hibernate.util.HibernateUtil;

public class SpellingTest {

	@Test
	public void testSave() {
		Spelling spb = new Spelling();
		spb.setWord("about");
		spb.setSchedule(new java.util.Date(System.currentTimeMillis()));

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;

		try {
			System.out.println("AAAAAAAAAAAAAAAAAAAAAAAA");
			transaction = session.beginTransaction();
			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>SPELLING_BEE ["
					+ session.save(spb) + "] Saved.");
			transaction.commit();

		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
	}
	@Test
	public void testRead() {
		//Spelling spb = new Spelling();

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		Session hsession = null;
		Session hsession1 = null;
		Transaction transaction = null;
		Subject subj = null;


		List vlist1 = new ArrayList();
		hsession1 = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria1 = (Criteria) hsession1.createCriteria(Spelling.class).uniqueResult();
		vlist1 = criteria1.list();
		
		Spelling spb = null;
		Iterator it1 = vlist1.iterator();
		
		while (it1.hasNext()) {
			spb = (Spelling)it1.next();
			System.out.println("<h3>"+spb.getSchedule()+"</h3>");
					
		}
	
	}
}
